<?php
class Users_Das extends Basic_Das {
	
	public function addUser($data = array()) {
		if (! is_array ( $data )) {
			throw new Exception ( "Users_Das: The parameter is not an array." );
		}
		
		$required = array ('USERID', 'PASSWORD', 'NICKNAME', 'REALNAME', 'GENDER', 'BIRTH', 'ADDRESS', 'PORTRAITPATH' );
		if (! $this->_required ( $required, $data )) {
			throw new Exception ( "Users_Das: Required field is missing." );
		}
		
		$data ['REGISTERTIME'] = date ( 'Y-m-d H:i:s' );
		
		$this->load->database ();
		$this->db->insert ( 'USERS', $data );
		$this->db->close ();
	}
	
	public function getUser($user_id) {
		if (! is_string ( $user_id )) {
			throw new Exception ("Users_Das: The parameter is not a string.");
		}
		
		$this->load->database ();
		
		$this->db->where ( 'USERID', $user_id );
		$this->db->from ( 'USERS' );
		$query = $this->db->get ();
		
		$this->db->close ();
		
		print_r ( $this->db->last_query () );
		print_r ( $query->result_array () );
		
		return $query->result_array ();
	}
	
	public function getUsers($ids) {
		if (! is_array ( $ids )) {
			throw  new Exception("Users_Das: The parameter is not an array.");
		}
		
		$this->load->database ();
		$this->db->where_in ( 'USERID', $ids );
		$query = $this->db->get ();
		
		return $query->result_array ();
	}
	
	public function updateUser($user_id, $data) {
		if (! is_string ( $user_id ) || ! is_array ( $data )) {
			throw new Exception("Users_Das: The type of parameter is wrong.");
		}
		
		$this->load->database ();
		$this->db->where ( 'USERID', $user_id );
		$this->db->update ( 'USERS', $data );
		
		$this->db->close ();
		
		print_r ( $this->db->last_query () );
		
		return true;
	}
}